<template>
	<view class="container">
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="formdata.telephone" placeholder="" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<uni-easyinput type="password" v-model="formdata.password" placeholder="" />
			</uni-forms-item>
		</uni-forms>
		<button type="primary" @click="login">登录</button>
		<button type="default"  @click="register">注册</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formdata: {
					"telephone": "12345678912",
					"password": "123456"
				}
			}
		},
		methods: {
login(){
	uni.request({
		url: 'http://localhost:8090/foodapp/user/login',
		method: 'POST',
		data: this.formdata,
		success: res => {
			if(res.data.success){
			uni.setStorageSync('user',res.data.data)
					uni.switchTab({
					url:"../my",
				});
			}else{
				uni.showToast({
					icon:"none",
					title:"用户名或密码错误"
				})
			}
		},
		fail: () => {
			uni.showToast({
				icon:"none",
				title:"网络错误"
			})
		},
		complete: () => {}
	});
},
register(){
	uni.navigateTo({
		url:"../register/register"
	})
}
		},
		onLoad: () => {
			uni.onTabBarMidButtonTap(function(e) {
				console.log(e)

			})
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
